package com.ningmengs789.live.live.live.common.widget.ready;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ningmengs789.live.Interface.RequestCallback;
import com.ningmengs789.live.R;
import com.ningmengs789.live.http.JsonBuilder;
import com.ningmengs789.live.http.OKHttpUtils;
import com.ningmengs789.live.live.live.common.widget.gift.view.AbsViewHolder;
import com.ningmengs789.live.live.live.push.TCLiveBasePublisherActivity;
import com.ningmengs789.live.server.widget.CircleImageView;
import com.bumptech.glide.Glide;

import org.json.JSONException;
import org.json.JSONObject;

public class DetailViewHolder extends AbsViewHolder implements View.OnClickListener{

    private TextView view_live_end_gold;

    public DetailViewHolder(Context context, ViewGroup parentView, String name_, String avatar_, String time_, String totalMemberCount_, String live_id) {
        super(context, parentView);

        TextView name = (TextView) findViewById(R.id.name);
        TextView btn_back = (TextView) findViewById(R.id.btn_back);
        btn_back.setOnClickListener(this);

        TextView duration = (TextView) findViewById(R.id.duration);
        TextView watch_num = (TextView) findViewById(R.id.watch_num);
        view_live_end_gold = (TextView) findViewById(R.id.view_live_end_gold);
        CircleImageView avatar = (CircleImageView) findViewById(R.id.avatar);

        Glide.with(mContext)
                .load(avatar_)
                .into(avatar);

        name.setText(name_);
        duration.setText(time_);
        watch_num.setText(totalMemberCount_);

        String body = "";
        try {
            body = new JsonBuilder()
                    .put("live_id", live_id)
                    .build();
        } catch (JSONException e) {
        }
        OKHttpUtils.getInstance().getRequest("app/live/afterCloseLive", body, new RequestCallback() {
            @Override
            public void onError(int errCode, String errInfo) {
            }
            @Override
            public void onSuccess(String result) {
                try {
                    JSONObject data = new JSONObject(result);
                    String curr_coin  = data.getString("curr_coin");
                    view_live_end_gold.setText(curr_coin);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    @Override
    protected int getLayoutId() {
        return R.layout.view_live_end;
    }

    @Override
    public void init() {
    }

    @Override
    public void onClick(View v) {
        if (!canClick()) {
            return;
        }
        int i = v.getId();
        if (i == R.id.btn_back) {
            ((TCLiveBasePublisherActivity) mContext).exit();
        }
    }
}